package com.newsmanagement.controller.backstage;

import com.newsmanagement.entity.ReturnedMessages;
import com.newsmanagement.service.IEumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author xbr
 * 2017.12.04 11:24
 * 后台系统 用户管理
 */
@Controller
@RequestMapping("eumBack")
public class EumController {

    @Autowired
    private IEumService eumService;

    /**
     * 添加用户
     * @param eumName 用户名
     * @param mobilePhone 手机号
     * @param password 密码
     * @return
     * http://localhost:8080/eumBack/add?eumName=xuhongliu&mobilePhone=18791091750&password=111111
     */
    @RequestMapping("add")
    @ResponseBody
    public ReturnedMessages addEum(
            @RequestParam(value = "eumName") String eumName,
            @RequestParam(value = "mobilePhone") String mobilePhone,
            @RequestParam(value = "password") String password
    ){

        return eumService.addEum(eumName ,mobilePhone ,password);
    }

    /**
     * 根据ID删除用户
     * @param eumId 用户Id
     * @return
     * http://localhost:8080/eumBack/delete?eumId=1
     */
    @RequestMapping("delete")
    @ResponseBody
    public ReturnedMessages deleteEum(HttpServletRequest request ,@RequestParam(value = "eumId") Long eumId){

        return eumService.deleteEum(eumId);
    }

    /**
     * 根据手机号登录
     * @param mobilePhone 手机号
     * @param password 密码
     * @return
     * http://localhost:8080/eumBack/login?mobilePhone=18791091750&password=111111
     *
     */
    @RequestMapping("login")
    @ResponseBody
    public ReturnedMessages login(
            HttpServletRequest request ,
            @RequestParam(value = "mobilePhone") String mobilePhone ,
            @RequestParam(value = "password") String password
    ){
        return eumService.login(request ,mobilePhone ,password);
    }

    /**
     * 设置用户对应角色
     * @param eumId 用户ID
     * @param roleId 角色ID
     * @return
     */
    @RequestMapping("eumToRole")
    @ResponseBody
    public ReturnedMessages eumToRole(
            @RequestParam(value = "eumId") Integer eumId ,
            @RequestParam(value = "roleId") Integer roleId
    ){

        return eumService.eumToRole(eumId ,roleId);
    }
}
